package pl.edu.pjwstk.kor.sbql4j.project3;

import pl.wcislo.sbql4j.db4o.Db4oSBQLQuery;
import com.db4o.*;
import com.db4o.ObjectContainer;

import com.db4o.foundation.*;

import com.db4o.internal.*;
import com.db4o.internal.btree.*;

import org.apache.commons.collections.CollectionUtils;

import pl.edu.pjwstk.kor.database.Database;
import pl.edu.pjwstk.kor.database.Sbql4jQuery;
import pl.edu.pjwstk.kor.model.Employee;
import pl.edu.pjwstk.kor.model.Rank;
import pl.edu.pjwstk.kor.model.Service;

import pl.wcislo.sbql4j.exception.*;
import pl.wcislo.sbql4j.java.model.runtime.*;
import pl.wcislo.sbql4j.java.model.runtime.Struct;
import pl.wcislo.sbql4j.java.model.runtime.factory.*;
import pl.wcislo.sbql4j.java.utils.ArrayUtils;
import pl.wcislo.sbql4j.java.utils.OperatorUtils;
import pl.wcislo.sbql4j.java.utils.Pair;
import pl.wcislo.sbql4j.lang.codegen.nostacks.*;
import pl.wcislo.sbql4j.lang.codegen.simple.*;




import pl.wcislo.sbql4j.lang.parser.expression.*;
import pl.wcislo.sbql4j.lang.parser.expression.OrderByParamExpression.SortType;
import pl.wcislo.sbql4j.lang.parser.terminals.*;
import pl.wcislo.sbql4j.lang.parser.terminals.operators.*;
import pl.wcislo.sbql4j.lang.types.*;
import pl.wcislo.sbql4j.lang.xml.*;
import pl.wcislo.sbql4j.model.*;
import pl.wcislo.sbql4j.model.collections.*;
import pl.wcislo.sbql4j.util.*;
import pl.wcislo.sbql4j.util.Utils;
import pl.wcislo.sbql4j.xml.model.*;
import pl.wcislo.sbql4j.xml.parser.store.*;

import java.util.*;
import java.util.Collection;


public class Project3Query_SbqlQuery2Db4o1 implements Db4oSBQLQuery {
    private java.util.List<java.lang.String> names;

    public Project3Query_SbqlQuery2Db4o1(java.util.List<java.lang.String> names) {
        this.names = names;
    }

    /**
     * query='db.(Employee where getBoss().getLastName() in names)'
    '
     **/
    public java.util.Collection<pl.edu.pjwstk.kor.model.Employee> executeQuery(
        final ObjectContainerBase ocb, final Transaction t) {
        final LocalTransaction transLocal = (LocalTransaction) t;
        final java.util.Collection<pl.edu.pjwstk.kor.model.Employee> _ident_Employee1 =
            new java.util.ArrayList<pl.edu.pjwstk.kor.model.Employee>();
        ClassMetadata _classMeta4 = ocb.classCollection()
                                       .getClassMetadata("pl.edu.pjwstk.kor.model.Employee");
        long[] _ids4 = _classMeta4.getIDs(transLocal);

        for (long _id4 : _ids4) {
            LazyObjectReference _ref4 = transLocal.lazyReferenceFor((int) _id4);
            _ident_Employee1.add((pl.edu.pjwstk.kor.model.Employee) _ref4.getObject());
        }

        java.util.Collection<pl.edu.pjwstk.kor.model.Employee> _whereResult1 = new java.util.ArrayList<pl.edu.pjwstk.kor.model.Employee>();
        int _whereLoopIndex1 = 0;

        for (pl.edu.pjwstk.kor.model.Employee _whereEl1 : _ident_Employee1) {
            if (_whereEl1 == null) {
                continue;
            }

            if (_whereEl1 != null) {
                ocb.activate(_whereEl1, 1);
            }

            pl.edu.pjwstk.kor.model.Employee _mth_getBossResult = _whereEl1.getBoss();

            if (_mth_getBossResult != null) {
                ocb.activate(_mth_getBossResult, 1);
            }

            pl.edu.pjwstk.kor.model.Employee _dotEl1 = _mth_getBossResult;

            if (_mth_getBossResult != null) {
                ocb.activate(_mth_getBossResult, 2);
            }

            java.lang.String _mth_getLastNameResult = _whereEl1.getLastName();

            if (_mth_getLastNameResult != null) {
                ocb.activate(_mth_getLastNameResult, 1);
            }

            java.util.List<java.lang.String> _ident_names = names;
            Collection _inLeftCol2 = new ArrayList();
            _inLeftCol2.add(_mth_getLastNameResult);

            Collection _inRightCol2 = new ArrayList(_ident_names);
            java.lang.Boolean _inResult1 = _inRightCol2.containsAll(_inLeftCol2);

            if (_inResult1) {
                _whereResult1.add(_whereEl1);
            }

            _whereLoopIndex1++;
        }

        pl.wcislo.sbql4j.db4o.utils.DerefUtils.activateResult(_whereResult1, ocb);

        return _whereResult1;
    }
}
